<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- 引入vue -->
  <script type="text/javascript" src="../js/vue.js"></script>
</head>

<body>
  <div id="root">
    <h1>学校信息</h1>
    <h2>名称：{{school.name}}</h2>
    <h2>地址：{{school.address}}</h2>
    <h2>校长：{{school.leader}}</h2>
    <hr>
    <h1>
      <button @click="addSex">添加一个性别属性，默认值是男</button>
      <h2>姓名：{{stu.name}}</h2>
      <h2 v-if="stu.sex">性别：{{stu.sex}}</h2>
      <h2>年龄：真实{{stu.age.rAge}},对外{{stu.age.sAge}}</h2>
      <h2>{{stu.name}}的朋友：</h2>
      <ul>
        <li v-for="(f,index) in stu.friends" :key='index'>
          {{f.name}} - {{f.age}}
        </li>
      </ul>
    </h1>
  </div>
  <script type="text/javascript">
    Vue.config.productionTip = false //阻止 vue 在启动时生成生产提示。、
    new Vue({
      el: '#root',
      data: {
        school: {
          name: '尚硅谷',
          address: '北京'
        },
        stu: {
          name: "李华",
          age: {
            rAge: 20,
            sAge: 22
          },
          friends: [
            { name: "张三", age: 18 },
            { name: "李四", age: 23 }
          ]
        }
      },
      methods: {
        addSex() {
          // Vue.set(this.stu, 'sex', '男')
          this.$set(this.stu,'sex','男')
        }
      },
    })
  </script>
</body>

</html>